package br.com.async.core.infrastructure;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;

import br.com.async.core.domain.bookmark.Bookmark;
import br.com.async.core.domain.bookmark.BookmarkRepository;
import br.com.async.core.domain.customer.Customer;

public class BookmarkRepositoryImpl extends AbstractRepositoryImpl<Bookmark, Integer> implements BookmarkRepository{

	public BookmarkRepositoryImpl() {
		super(Bookmark.class);
	}
	
	public Boolean isBookmarked(Integer customerCode, Integer EnterpriseCode){
		
		Criteria criteria = getSession().createCriteria(Customer.class);
		Criterion c1 = Restrictions.eq("code", customerCode);
		criteria.add(c1);
		
		Customer customer = (Customer) criteria.uniqueResult();
		List<Bookmark> list = customer.getBookmark();
		
		for (Bookmark bookmark : list) {
			
			if(bookmark.getEnterprise().getCode().equals(EnterpriseCode)){
				return true;
			}
		}
		return false;
		
	}
	
}
